<div class="layui-card-header layui-card">
    <span class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">首页</a>
        <a><cite>结算列表</cite></a>
    </span>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">结算列表信息</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show" style="margin-bottom:1%;">
                    <div class="layui-row" style="float:right; margin-bottom: 10px;">
                        <div class="layui-form" style="float:right;">
                            <div class="layui-form-item" style="margin:0;">
                                <div class="layui-input-inline">
                                    <input type="text" name="createTimeStart" id="createTimeStart" autocomplete="off" placeholder="开始时间" class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <input type="text" name="createTimeEnd" id="createTimeEnd" autocomplete="off" placeholder="结束时间" class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <input type="text" name="accountName" id="accountName" placeholder="账户名" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <input type="text" name="settOrderId" id="settOrderId" placeholder="结算单号" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <select name="settStatus" id="settStatus" lay-search="">
                                        <option value="-99">状态</option>
                                        <option value="1">等待审核</option>
                                        <option value="2">已审核</option>
                                        <option value="3">审核不通过</option>
                                        <option value="4">打款中</option>
                                        <option value="5">打款成功</option>
                                        <option value="6">打款失败</option>
                                    </select>
                                </div>
                                <button id="search" class="layui-btn" data-type="reload">搜索</button>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <blockquote class="layui-elem-quote" id="amountTip">
                            订单数:<sapn id="allTotalCount" style="color: blue; margin-right: 10px;"></sapn>
                            结算金额:<span id="allTotalAmount" style="color: blue; margin-right: 10px;"></span>
                            结算费用:<span id="allTotalFee" style="color: green; margin-right: 10px;"></span>
                        </blockquote>
                    </div>
                </div>
                <table id="jsList"></table>
            </div>
        </div>
    </div>
</div>
<script>
     //标题内容模板
     var tplTitle = function(d){
         return '<a class="layui-btn layui-btn-xs layui-btn-primary" lay-href="sett/detail/id='+ d.id +'">详情</a>';
     };

     var tplStatus = function(d){
         if(d.settStatus == 1) {
             return "<span style='color: red'>等待审核</span>";
         }else if(d.settStatus == 2) {
             return "<span style='color: darkgreen'>已审核</span>";
         }else if(d.settStatus == 3) {
             return "<span style='color: indigo'>审核不通过</span>";
         }else if(d.settStatus == 4) {
             return "<span style='color: blue'>打款中</span>";
         }else if(d.settStatus == 5) {
             return "<span style='color: brown'>打款成功</span>";
         }else if(d.settStatus == 6) {
             return "<span style='color: #122b40'>打款失败</span>";
         }
     };

     layui.use(['table','util','admin', 'laydate', 'form'], function(){
        var table = layui.table
        ,$ = layui.$
        ,admin = layui.admin
        ,form = layui.form
        ,laydate = layui.laydate
        ,element = layui.element;

        element.render('breadcrumb', 'breadcrumb');//渲染导航信息

         $.setCountResult = function(accountName, settOrderId, settStatus, createTimeStart, createTimeEnd) {
             admin.req({
                 type: 'get',
                 url: layui.setter.baseUrl + '/sett/count',
                 data: {
                     accountName : accountName,
                     settOrderId : settOrderId,
                     settStatus : settStatus,
                     createTimeStart : createTimeStart,
                     createTimeEnd : createTimeEnd
                 },
                 error: function(err){
                     layer.alert(JSON.stringify(err.field), {
                         title: '错误提示'
                     })
                 },
                 success: function(res){
                     if(res.code == 0){
                         $('#allTotalCount').html(res.data.allTotalCount);
                         $('#allTotalAmount').html("￥" + res.data.allTotalAmount/100.00);
                         $('#allTotalFee').html("￥" + res.data.allTotalFee/100.0);
                     }
                 }
             });
         };

         // 初始化统计结果
         $.setCountResult();

        table.render({
            elem: '#jsList'
            ,url: layui.setter.baseUrl + '/sett/list'
            ,where: {
                access_token: layui.data(layui.setter.tableName).access_token
            }
            ,id: 'tableReload'
            ,cols: [[
                {field:'settOrderId', width: 220, title: '结算单号', sort: true }
                /*,{field: 'settType',title: '结算类型',templet: '<div>{{d.settType == 1?"手工结算":d.settType == 2?"自动结算":""}}</div>'}*/
                ,{field:'accountName', title: '账户名' }
                ,{field:'settAmount', title: '结算金额',templet: '<div>{{d.settAmount/100}}</div>' }
                ,{field:'settFee', title: '手续费',templet: '<div>{{d.settFee/100}}</div>' }
                ,{field:'remitAmount', title: '打款金额',templet: '<div>{{d.remitAmount/100}}</div>' }
                ,{field: 'settStatus',title: '结算状态',templet: tplStatus}
                ,{field: 'settDate',title: '结算日期',templet: '<div>{{ layui.util.toDateString(d.settDate, "yyyy-MM-dd") }}</div>'}
                ,{field:'edite', title: '操作', templet: tplTitle }
            ]]
            ,page: true
            ,skin: 'line'
        });

         // 搜索
         var $ = layui.$, active = {
             reload: function(){
                 var createTimeStart = $('#createTimeStart').val();
                 var createTimeEnd = $('#createTimeEnd').val();
                 var settOrderId = $('#settOrderId').val();
                 var accountName = $('#accountName').val().trim();;
                 var settStatus = $("#settStatus").val();
                 $.setCountResult(accountName, settOrderId, settStatus, createTimeStart, createTimeEnd);
                 //执行重载
                 table.reload('tableReload', {
                     page: {
                         curr: 1 //重新从第 1 页开始
                     }
                     ,where: {
                         settOrderId: settOrderId,
                         accountName: accountName,
                         createTimeStart : createTimeStart,
                         createTimeEnd : createTimeEnd,
                         settStatus : settStatus
                     }
                 });
             }
         };
         $('#search').on('click', function() {
             var type = $(this).data('type');
             active[type] ? active[type].call(this) : '';
         });

         laydate.render({
             elem: '#createTimeStart'
             ,type: 'datetime'
             ,format: 'yyyy-MM-dd HH:mm:ss'
         });

         laydate.render({
             elem: '#createTimeEnd'
             ,type: 'datetime'
             ,format: 'yyyy-MM-dd HH:mm:ss'
         });

         // 渲染表单
         form.render();
        
     })
</script>